
/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

package org.zxy.cxf;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.logging.Logger;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

/**
 * This class was generated by Apache CXF 3.0.4
 * 2015-03-13T00:01:34.583+08:00
 * Generated source version: 3.0.4
 * 
 */

@javax.jws.WebService(
                      serviceName = "MyServiceImplService",
                      portName = "MyServiceImplPort",
                      targetNamespace = "http://cxf.zxy.org/",
                      wsdlLocation = "file:/C:/myservice.wsdl",
                      endpointInterface = "org.zxy.cxf.MyService")
                      
public class MyServiceImplPortImpl implements MyService {

    private static final Logger LOG = Logger.getLogger(MyServiceImplPortImpl.class.getName());

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#sayHello(java.lang.String  arg0 ,)java.lang.String  arg1 ,)java.lang.String  arg2 )*
     */
    public java.lang.String sayHello(java.lang.String arg0,java.lang.String arg1,java.lang.String arg2) { 
        LOG.info("Executing operation sayHello");
        System.out.println(arg0);
        System.out.println(arg1);
        System.out.println(arg2);
        try {
           return arg0+","+arg1+","+arg2;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#uploadFile(org.zxy.cxf.FileType  parameters )*
     */
    public void uploadFile(FileType parameters) { 
        LOG.info("Executing operation uploadFile");
        System.out.println(parameters.getClass());
        try {
        	byte[] content = parameters.getFileContent();
        	OutputStream os = new FileOutputStream(new File("c:/copy.wsdl"));
        	os.write(content);
        	os.close();
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#getStudentById(org.zxy.cxf.IdType  parameters )*
     */
    public org.zxy.cxf.ArrayOfStudentType getStudentById(IdType parameters) { 
        LOG.info("Executing operation getStudentById");
        System.out.println(parameters);
        try {
        	ArrayOfStudentType array = new ArrayOfStudentType();
        	StudentType student1 = new StudentType();
        	student1.setName("zhangsan");student1.setAddress("beijing");
        	StudentType student2 = new StudentType();
        	student2.setName("lisi");student2.setAddress("shanghai");
        	array.getStudents().add(student1);array.getStudents().add(student2);
        	return array;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#showLight(org.zxy.cxf.LightType  parameters )*
     */
    public org.zxy.cxf.IdType showLight(LightType parameters) { 
        LOG.info("Executing operation showLight");
        System.out.println(parameters);
        try {
        	IdType idType = new IdType();
            if(parameters.equals(LightType.RED)) {
            	idType.setId(1);
            	return idType;
            }else if (parameters.equals(LightType.YELLOW)) {
				idType.setId(2);
				return idType;
			}else {
				idType.setId(3);
				return idType;
			}
            	
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#uploadFileByMTOM(org.zxy.cxf.FileType  parameters )*
     */
    public void uploadFileByMTOM(FileMTOMType parameters) { 
        LOG.info("Executing operation uploadFileByMTOM");
        System.out.println(parameters.getClass());
        try {
        	DataHandler dataHandler = parameters.getFileContent();
			System.out.println(dataHandler.getName());

			InputStream is = dataHandler.getInputStream();
			OutputStream os = new FileOutputStream("c:/test.chm");

			int length = 0;
			byte[] buffer = new byte[2048];

			while (-1 != (length = is.read(buffer)))
			{
				os.write(buffer, 0, length);
			}

			is.close();
			os.close();
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    /* (non-Javadoc)
     * @see org.zxy.cxf.MyService#queryByProductName(org.zxy.cxf.NameType  parameters )*
     */
    public org.zxy.cxf.OrderType queryByProductName(NameType parameters) { 
        LOG.info("Executing operation queryByProductName");
        System.out.println(parameters.getName());
        try {
        	OrderType orderType = new OrderType();
        	orderType.setId(100);
        	orderType.setOrderDate(javaDate2XMLGregorianCalendar(new Date()));
        	orderType.setOrderName("taobao");
        	orderType.setOwner("mayun");
        	return orderType;
        } catch (java.lang.Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
    }

    private XMLGregorianCalendar javaDate2XMLGregorianCalendar(Date date) throws DatatypeConfigurationException{
    	GregorianCalendar gregorianCalendar = new GregorianCalendar();
    	gregorianCalendar.setTime(date);
		XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
		return xmlGregorianCalendar;
    }
}
